package com.shop.dao.impl;

import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Repository;

import com.shop.dao.CommentDao;
import com.shop.domain.Comment;
import com.shop.util.MyBatisUtil;

/**
 * 
 * @author wenjuanhenxing
 * @version V1.0 CommentDaoImpl.java 2016-2-11 上午7:26:58
 */
@Repository("commentDaoImpl")
public class CommentDaoImpl implements CommentDao {

	@Override
	public boolean addComment(Comment comment) {
		if (comment == null) {
			return false;
		}
		SqlSession sqlSession = MyBatisUtil.getSqlSession(true);
		int rowsAffected = sqlSession.insert(
				"com.shop.dao.mapping.CommentMapper" + ".addComment", comment);
		MyBatisUtil.closeSession(sqlSession);
		return rowsAffected == 1;

	}

	@Override
	public boolean deleteCommentById(Long id) {
		SqlSession sqlSession = MyBatisUtil.getSqlSession(true);
		int rowsAffected = sqlSession
				.delete("com.shop.dao.mapping.CommentMapper"
						+ ".deleteCommentById", id);
		MyBatisUtil.closeSession(sqlSession);
		return rowsAffected == 1;
	}

}
